from django.db import models


# Create your models here.

class City(models.Model):
    code = models.CharField(max_length=50, primary_key=True, verbose_name="城市代码")
    name = models.CharField(max_length=50, verbose_name="城市名称")
    fcd = models.DateTimeField(verbose_name="创建时间", help_text="创建时间", auto_now_add=True)
    lcd = models.DateTimeField(verbose_name="更新时间", help_text="更新时间", auto_now=True)
    host_count = models.IntegerField(verbose_name="主机数量", default=0)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'host_city'


class Room(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=50, verbose_name="房间名称")
    city = models.ForeignKey(City, on_delete=models.PROTECT, verbose_name="城市", help_text="城市")
    fcd = models.DateTimeField(verbose_name="创建时间", help_text="创建时间", auto_now_add=True)
    lcd = models.DateTimeField(verbose_name="更新时间", help_text="更新时间", auto_now=True)
    host_count = models.IntegerField(verbose_name="主机数量", default=0)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'host_room'


class Host(models.Model):
    id = models.AutoField(primary_key=True)
    ip = models.CharField(max_length=20, unique=True, verbose_name="主机ip")
    name = models.CharField(max_length=50, verbose_name="主机名称")
    room = models.ForeignKey(Room, on_delete=models.PROTECT, verbose_name="机房", help_text="机房")
    fcd = models.DateTimeField(verbose_name="创建时间", help_text="创建时间", auto_now_add=True)
    lcd = models.DateTimeField(verbose_name="更新时间", help_text="更新时间", auto_now=True)
    password = models.BinaryField(verbose_name="主机加密密码")

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'host_host'